package com.quanyue.haircut.user.job;

import com.quanyue.haircut.domain.entity.Manager;
import com.quanyue.haircut.user.mapper.HaircutMerchantMapper;
import com.quanyue.haircut.user.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
public class ManagerJob {
    @Autowired
    private HaircutMerchantMapper merchantMapper;
    @Autowired
    private ManagerService managerService;


    // 管理员过期校检
    @Scheduled(cron = "0 0 0/1 * * ?")
    public void checkCouponExpires() {
        merchantMapper.findAllValid().forEach(merchant -> {
            if (merchant.getExpireTime().compareTo(LocalDate.now()) <= 0) {
                Manager manager = managerService.findByMerchantNo(merchant.getMerchantNo());
                if (manager == null) return;
                managerService.remove(manager.getId());
            }
        });

    }
}
